package com.baiyinet.util;


import android.content.Context;
import android.content.pm.ApplicationInfo;

import com.baiyinet.BuildConfig;
import com.jude.utils.JUtils;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import java.util.List;

/**
 * @author J.Huang
 * @version 1.0
 */
public class AppUtils {
    public static int getAppVersionCode() {
        return JUtils.getAppVersionCode();
    }

    public static String getAppVersionName() {
        return JUtils.getAppVersionName();
    }

    public static boolean isWXAppInstalled(Context context) {
        List<ApplicationInfo> list = context.getPackageManager().getInstalledApplications(0);

        for (ApplicationInfo info :
                list) {
            if ("com.tencent.mm".equals(info.packageName)) {
                return true;
            }
        }

        return false;
    }

    public static boolean isQQAppInstalled(Context context) {
        List<ApplicationInfo> list = context.getPackageManager().getInstalledApplications(0);

        for (ApplicationInfo info :
                list) {
            if ("com.tencent.mobileqq".equals(info.packageName)) {
                return true;
            }
        }

        return false;
    }

    public static boolean isWxAppSupported(Context context) {
        IWXAPI msgApi = WXAPIFactory.createWXAPI(context, BuildConfig.WECHAT_APP_ID);
        msgApi.registerApp(BuildConfig.WECHAT_APP_ID);

        return msgApi.isWXAppInstalled();
//                && msgApi.isWXAppSupportAPI();
    }
}
